import { computed, ref, unref, watch } from 'vue';

const useLoading = (props, field = 'loading') => {
  const loadingRef = ref(unref(props)[field]);

  const getLoading = computed(() => unref(loadingRef));

  watch(
    () => unref(props)[field],
    (loading) => {
      loadingRef.value = loading;
    },
  );

  const setLoading = (loading) => {
    loadingRef.value = loading;
  };

  return {
    getLoading,
    setLoading,
  };
};

export default useLoading;
